{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "#### 数学链LLMMathChain(了解)\n",
    "    LLMMathChain将用户问题转换为数学问题，然后将数学问题转换为可使用Python的numexpr库执行的表达式。\n",
    "    使用运行此代码的输出来回答问题。\n",
    "    使用LLMMathChain，需要安装numexpr库"
   ],
   "id": "3895f5c62c258f95"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from langchain.chains.llm_math.base import LLMMathChain\n",
    "from langchain_openai import ChatOpenAI\n",
    "import os\n",
    "\n",
    "os.environ['OPENAI_BASE_URL'] = 'https://vip.apiyi.com/v1'\n",
    "os.environ['OPENAI_API_KEY'] = 'sk-xU64G4hXJ4L47ko3764958119dB245D2BdEcE528767dA1Da'\n",
    "\n",
    "# 创建大模型实例\n",
    "chat_model = ChatOpenAI(model=\"gpt-4o-mini\")\n",
    "\n",
    "# 创建链\n",
    "llm_math = LLMMathChain.from_llm(chat_model)\n",
    "\n",
    "# 执行链\n",
    "res = llm_math.invoke(\"10 ** 3 + 100的结果是多少?\")\n",
    "print(res)"
   ],
   "id": "9d8a765fbd098013",
   "outputs": [],
   "execution_count": null
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
